#include "main.h"

const int offset_table[] = {
-5, -5, -5, -5, -5, -5, -5, -5, -5, -5,              // -10 ~ -1
-5, -5, -5, -5, -5, -5, -5, -5, -5, -5,              // 0 ~ 9
-5, -5, -5, -4, -3, -2, -1, 0, 1, 2,              // 10 ~ 19
3, 4, 5, 5, 5, 5, 5, 5, 5, 6,              // 20 ~ 29
7, 8, 8, 8, 9, 9, 10, 10, 10, 11,          // 30 ~ 39
11, 11, 11, 12, 13, 14, 14, 14, 14, 14,    // 40 ~ 49
14, 15, 15, 15, 16, 16, 16, 17, 17, 17,    // 50 ~ 59
18, 18, 18, 18, 19, 19, 19, 20, 20, 20,    // 60 ~ 69
21, 21, 21, 21, 21, 21, 21, 21, 21, 21,    // 70 ~ 79
21, 21, 21, 21, 21, 21, 21, 22, 22, 22,    // 80 ~ 89
23, 23, 23, 23, 23, 23, 23, 23, 23, 23,    // 90 ~ 99
23};                                       // 100

double adjust(double din)
{

	double real_value = 0.0;
	int index;

	real_value = din;

	// 4.7k电阻
	real_value = real_value - 43;

	// 低于-9.9度的处理
	if (real_value<-99)
		real_value = -99;

	// 超过设定温度的处理
	if (real_value>TEMP_LIMITED)
		real_value = TEMP_LIMITED;

	if (real_value>40)
		real_value = real_value - (real_value-40)*0.068;

	// 每一度的修正范围为当前温度+/- 0.5度范围
	index = (real_value+5)/10 + 10;
	real_value += offset_table[index];

	return real_value;

}
